//! \file UiWindowMain.c
//! \brief TODO: Document
// -----------------------------------------------------------------------------
//! This program is free software; you can redistribute it and/or
//! modify it under the terms of the GNU General Public License
//! as published by the Free Software Foundation; either version 2
//! of the License, or (at your option) any later version.
//!
//! This program is distributed in the hope that it will be useful,
//! but WITHOUT ANY WARRANTY; without even the implied warranty of
//! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//! GNU General Public License for more details.
//!
//! You should have received a copy of the GNU General Public License
//! along with this program; if not, write to the Free Software Foundation,
//! Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
// -----------------------------------------------------------------------------

#include <agar/core.h>
#include <agar/gui.h>

#include "UiWindowMain.h"
#include "UiMenu.h"
#include "UiConsole.h"
#include "UiDraw.h"

// =====[ Local Definitions ]===================================================

// =====[ Local DataTypes ]=====================================================

// =====[ Local Variables ]=====================================================
static AG_Window *pWindow;

// =====[ Local Functions ]=====================================================

// =====[ Private (Internal) Methods ]==========================================

// =====[ Local Implementation ]================================================


// =============================================================================
// Implement: UI_WindowMainNew
// -----------------------------------------------------------------------------
tERROR UI_WindowMainNew(void)
{
  AG_Pane *pPaneHoriz, *pPaneVert;
//  AG_Pixmap *pPixmap;
  extern AG_Pixmap *pPixmap;
  AG_Surface* pMyImage;


  // Create the console window.
//  pWindow = AG_WindowNew(AG_WINDOW_PLAIN | AG_WINDOW_KEEPABOVE | AG_WINDOW_MAXIMIZED);
  pWindow = AG_WindowNew(AG_WINDOW_PLAIN);
  AG_WindowSetPadding(pWindow, 0, 0, 0, 0);
  AG_WindowSetGeometry(pWindow, 0, 0, 640, 480);

  pMyImage = AG_SurfaceFromBMP("hello.bmp"); // TODO: cleanup

  // Attach the user interface menu.
  UI_MenuNew((AG_Widget*)pWindow);              // Attach the dungeon quest menu.

  // Divide the window vertically.
  pPaneVert = AG_PaneNewVert(pWindow, AG_PANE_EXPAND);
  {
    // Divide the left pane horizontally.
    pPaneHoriz = AG_PaneNewHoriz(pPaneVert->div[0], AG_PANE_EXPAND);
    AG_LabelNew(pPaneHoriz->div[0], 0, "Left/Top");
    //pPixmap = AG_PixmapFromSurface(pPaneHoriz->div[1], 0, pMyImage);
    //pPixmap = AG_PixmapNew(pPaneHoriz->div[1], 0, 1024, 1024);
    UI_DrawNew(pPaneHoriz->div[1]);

//    pPaneHoriz->div[1].

    AG_PaneMoveDividerPct(pPaneVert, 70);
  }
  UI_ConsoleNew(pPaneVert->div[1]);             // Attach the dungeon quest console.
  AG_PaneMoveDividerPct(pPaneHoriz, 20);
  AG_WindowMaximize(pWindow);                   // Use the entire host window.

  // Finally, show window.
  AG_WindowShow(pWindow);

  // TODO: error checking?
}

